home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1997 February / PC Shareware 1997-02.iso / programy / e! / api / mulhelp2.c_ / mulhelp2.C
Encoding:
C/C++ Source or Header  |  1995-03-05  |  8.8 KB  |  256 lines

  1. /*************************************************
  2. *                                                *
  3. * E! for Windows                                 *
  4. * (c) - Patrick Philippot - 1992,1993            *
  5. *                                                *
  6. * MulHelp2 Extension DLL - version 2.1           *
  7. *                                                *
  8. * Supporting multiple Help Files from E!.        *
  9. *                                                *
  10. *************************************************/
  11.  
  12. /*
  13. MULHELP2 is a much more sophisticated version of MULHELP. There are
  14. many situations where you have to refer to multiple help files. For
  15. example, when writing Visual C++ source code with E!, you may want
  16. to refer to the Windows 3.1 SDK, the MFC 2.5 and the C/C++ language
  17. help files. It would be nice to load one of this file at will when
  18. the cursor is located on a keyword.
  19.  
  20. With MULHELP2 you can.
  21.  
  22. With MULHELP, each alternate help file was assigned a different key.
  23. MULHELP2 has another approach. When you hit SHIFT+F1 (or the key that
  24. you have assigned to the AlternateHelp function), a listbox is
  25. displayed, showing the list of all the alternate help files that you
  26. have specified in EW.INI. Select one of these and WinHelp will be
  27. called with the selected help file and the current keyword as
  28. parameters.
  29.  
  30. But there's more to MULHELP2, however. This DLL installs a hook on the
  31. JumpToDefinition function. When you ask E! to jump to a function definition
  32. and when E! can't find this definition in the TAG file, MULHELP2 takes
  33. control and asks the user whether he wants the keyword to be passed to
  34. one of the registered help files.
  35.  
  36.  
  37. Installing MULHELP2
  38. *******************
  39.  
  40. The first thing you have to do is to create a new section in EW.INI:
  41. [extended help]. Then, you will list in that section the help files
  42. you want to use, as follows (this is an example):
  43.  
  44. HelpName1=win31wh.hlp
  45. HelpName2=mfc.hlp
  46. HelpName3=mscxx.hlp
  47.  
  48. You must then add a description for each of these files:
  49.  
  50. HelpDesc1=Windows SDK Help File
  51. HelpDesc2=MFC 2.5 Help File
  52. HelpDesc3=Microsoft C/C++ Language Help File
  53.  
  54. and so on...
  55.  
  56. You should then load MULHELP2 from the User menu (you can also
  57. install MULHELP2 as an autoloaded EWD). MULHELP2.EWD must reside in
  58. your USER directory.
  59.  
  60. WARNING!!
  61.  
  62. If you had previously installed MULHELP.EWD, you should unload it,
  63. remove it from your autoload list if necessary and remove any
  64. assignment to the SHIFT+F1 key (or to the key to which you have
  65. assigned the AlternateHelp function).
  66.  
  67. Once MULHELP2 is loaded, when you hit SHIFT+F1, the list of help
  68. file descriptors will be displayed and you'll just have to select
  69. one to get help about the current keyword if it is relevant for the
  70. selected help file.
  71.  
  72.  
  73. Enjoy!
  74.  
  75. Patrick Philippot
  76. 01-12-95
  77. */
  78.  
  79. #include <windows.h>
  80. #include "ewapi2.h"
  81. #include <stdlib.h>
  82. #include <string.h>
  83.  
  84.   char HelpEntry[]   = "HelpName";
  85.   char HelpDesc[]    = "HelpDesc";
  86.   char HelpSection[] = "Extended Help";
  87.   char Profile[]     = "ew.ini";
  88.  
  89. #define id_ListBox  100
  90.  
  91.   char EntryValue[81];
  92.   char HelpCurEntry[81];
  93.   HWND ListBoxHandle, OkBtHandle;
  94.   HANDLE hInst;
  95.  
  96.  
  97. BOOL CALLBACK ChoiceDlg(HWND hwndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
  98. //  This is the dialog procedure managing the Help File Description List
  99. {
  100.   int Index ;
  101.   char IndexStr[4];
  102.  
  103.   switch (Message)
  104.   {
  105.     case WM_INITDIALOG:
  106.        // Get handle of Listbox
  107.         ListBoxHandle = GetDlgItem(hwndDlg, id_ListBox);
  108.         OkBtHandle = GetDlgItem(hwndDlg, IDOK);
  109.         EnableWindow(OkBtHandle, FALSE);
  110.         SetFocus(ListBoxHandle);
  111.        // Fill listbox with name of registered help files
  112.         Index = 1;
  113.         _itoa(Index, IndexStr, 10);
  114.         _fstrcat(_fstrcpy(HelpCurEntry, HelpDesc), IndexStr);
  115.        // Iterate through list of help file descriptors
  116.         while (GetPrivateProfileString(HelpSection,
  117.                                        HelpCurEntry,
  118.                                        "",
  119.                                        EntryValue,
  120.                                        sizeof(EntryValue),
  121.                                        Profile) != 0)
  122.          {
  123.           // Add descriptor to Listbox
  124.            SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) EntryValue);
  125.            Index++;
  126.            _itoa(Index, IndexStr, 10);
  127.            _fstrcat(_fstrcpy(HelpCurEntry, HelpDesc), IndexStr);
  128.          }
  129.         return TRUE;
  130.     case WM_COMMAND:
  131.         switch (wParam)
  132.         {
  133.           case id_ListBox:
  134.               if (HIWORD(lParam) != LBN_DBLCLK)
  135.              // A double_click is processed as the IDOK command
  136.               {
  137.                 if (HIWORD(lParam) == LBN_SELCHANGE)
  138.                 {
  139.                   EnableWindow(OkBtHandle, TRUE);
  140.                   return TRUE;
  141.                 }
  142.                 else
  143.                   return FALSE;
  144.               }
  145.           case IDOK:
  146.               Index = SendMessage(ListBoxHandle, LB_GETCURSEL, 0, 0);
  147.               if (Index != LB_ERR)
  148.              // A Help File Descriptor is currently selected
  149.               {
  150.                 _itoa(Index + 1, IndexStr, 10);
  151.                 _fstrcat(_fstrcpy(HelpCurEntry, HelpEntry), IndexStr);
  152.                // Get the corresponding help filename
  153.                 if (GetPrivateProfileString(HelpSection,
  154.                                             HelpCurEntry,
  155.                                             "",
  156.                                             EntryValue,
  157.                                             sizeof(EntryValue),
  158.                                             Profile) != 0)
  159.                  // It is important to close the dialog box before calling an E! API
  160.                  // function. Otherwise, E! is unable to know which Edit Window is active
  161.                   {
  162.                     EndDialog(hwndDlg, IDOK);
  163.                     WritePrivateProfileString("system",
  164.                                               "alternatehelp",
  165.                                               EntryValue,
  166.                                               Profile);
  167.                     EWAlternateHelp(EWGetCaretPosX(), EWGetCaretPosY());
  168.                     return TRUE;
  169.                   }
  170.                 else
  171.                // No Help Filename could be found for the Descriptor with this index
  172.                 {
  173.                   MessageBeep(0);
  174.                   EWMessageBox(GetFocus(),
  175.                               "Can't find related Help File.",
  176.                               "Error!",
  177.                               MB_OK | MB_ICONEXCLAMATION);
  178.                 }
  179.               }
  180.               else
  181.               {
  182.                 MessageBeep(0);
  183.                 EWMessageBox(GetFocus(),
  184.                              "No Help File Selected.",
  185.                              "Error!",
  186.                              MB_OK | MB_ICONEXCLAMATION);
  187.               };
  188.           case IDCANCEL:
  189.               EndDialog(hwndDlg, IDCANCEL);
  190.               return TRUE;
  191.         }
  192.      default:
  193.        return FALSE;
  194.   }
  195. }
  196.  
  197. int FAR PASCAL _export FuncEntryHook(unsigned int command)
  198. // Install a hook for the AlternateHelp function.
  199. {
  200.   static BOOL bInUse = FALSE;
  201.   DLGPROC ChoiceProc;
  202.  
  203.   if ((!bInUse) && (command == ew_AlternateHelp))
  204.   {
  205.     bInUse = TRUE;
  206.     ChoiceProc = (DLGPROC) MakeProcInstance(ChoiceDlg, hInst);
  207.     DialogBox(hInst, "HelpList", GetFocus(), ChoiceProc);
  208.     FreeProcInstance((FARPROC) ChoiceProc);
  209.     bInUse = FALSE;
  210.     return 1;
  211.   }
  212.   else
  213.     return 0;
  214. }
  215.  
  216. int FAR PASCAL _export FuncExitHook(unsigned int command, int FAR* pRetcode)
  217. // Check whether the JumpToDef function succeeded.
  218. // If not, ask the user whether the keyword should be passed to a help file
  219. {
  220.   if ((command == ew_MCJumpToDef) && (*pRetcode != 0))
  221.     if (EWMessageBox(GetFocus(),
  222.                      "No Definition found for this function. Pass Keyword to a Help File?",
  223.                      "Error",
  224.                      MB_YESNO) == IDYES)
  225.         *pRetcode = EWAlternateHelp(EWGetCaretPosX(), EWGetCaretPosY());
  226.  // Although the current version of the EW API doesn't check the return code
  227.  // from the FuncExitHook functions, it is good practice to set this value
  228.  // to 0.
  229.   return 0;
  230. }
  231.  
  232. int FAR PASCAL _export _WEP(int nExitType)
  233. {
  234.  // Uninstall Hook before exiting}
  235.   EWRemoveHook(EWHook_FunctionEntry, FuncEntryHook);
  236.   EWRemoveHook(EWHook_FunctionExit, FuncExitHook);
  237.  
  238.   return 1;
  239. }
  240.  
  241. int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
  242.                         LPSTR lpszCmdLine)
  243. {
  244.   hInst = hInstance;
  245.  
  246.   if (wHeapSize > 0)
  247.     UnlockData (0) ;
  248.  
  249.  // Install Function Entry Hook on the AlternateHelp function
  250.   EWSetHook(EWHook_FunctionEntry, FuncEntryHook);
  251.   EWSetHook(EWHook_FunctionExit, FuncExitHook);
  252.  
  253.   return 1;
  254. }
  255.  
  256.